package com.github.gaojh.ioc;


import cn.hutool.core.convert.Convert;
import com.github.gaojh.ioc.bean.FlyingIoc;
import com.github.gaojh.ioc.bean.Ioc;

import java.util.List;


/**
 * <p>
 *
 * </p>
 *
 * @author gaojh
 * @since 2020/3/20
 */
public class IocUtil {

    private static final Ioc ioc = new FlyingIoc();

    public static void addBean(Object object) {
        ioc.addBean(object);
    }

    public static void addBean(String name, Object object) {
        ioc.addBean(name, object);
    }

    public static Object getBean(String name) {
        return ioc.getBean(name);
    }

    public static <T> T getBean(Class<T> clazz) {
        return ioc.getBean(clazz);
    }

    public static <T> T getBean(Class<T> clazz, String name) {
        Object o = getBean(name);
        if (o == null) {
            return null;
        }
        return Convert.convert(clazz, o);
    }

    public static <T> List<T> getBeansByInterface(Class<T> tClass) {
        return ioc.getBeansByInterface(tClass);
    }

    public static <T> List<T> getBeansByType(Class<T> tClass) {
        return ioc.getBeansByType(tClass);
    }

    public static List<Object> getAllBeans(){
        return ioc.getAllBeans();
    }
}
